<?php
require_once("vcl/vcl.inc.php");
require_once("lib/db_connection.php");
//Includes
use_unit("components4phpfull/jtdivwindow.inc.php");
use_unit("components4phpfull/jtgroupbox.inc.php");
use_unit("menus.inc.php");
use_unit("components4phpfull/jtjavascript.inc.php");
use_unit("components4phpfull/jtsitetheme.inc.php");
use_unit("platinumgrid/jtplatinumgrid.inc.php");
use_unit("forms.inc.php");
use_unit("extctrls.inc.php");
use_unit("stdctrls.inc.php");

//Class definition
class tire_list extends Page
{
       public $JTDivInfo = null;
       public $JTGroupBox5 = null;
       public $Label13 = null;
       public $imgInfo = null;
       public $btnSearch = null;
       public $edtSearch = null;
       public $Image4 = null;
       public $JTJavaScript1 = null;
       public $hfSearch = null;
       public $JTTireList = null;
       public $imgAdd = null;
       public $Image1 = null;
       public $JTSiteTheme1 = null;
       function imgInfoJSClick($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.getElementById('JTDivInfo').Show();
       <?php

       }




       function edtSearchJSClick($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.getElementById('edtSearch').value = '';
       <?php

       }

       function btnSearchClick($sender, $params)
       {
        redirect('tire_list.php?search='.$this->edtSearch->Text);
       }

       function tire_listCreate($sender, $params)
       {
       $this->imgAdd->setLink('tire_general_create.php');
       $search = $_GET['search'];
       if($search!=null || $search!='' || isset($search))
       {
        $this->hfSearch->setValue($search);
       }

       if($_SESSION['access_tire']==1)
       {
       $this->imgAdd->Visible=false;
       }

       if($_SESSION['access_tire']==2)
       {
       $this->imgAdd->Visible=true;
       }

       }

       function JTTireListShow($sender, $params)
       {
       $search = $this->hfSearch->getValue();
       $query1 = "select * from tire_inventory_tbl where company_id='".$_SESSION['company_id']."'
       AND
       (purch_date like '%".$this->edtSearch->Text."%'
       OR tire_SN like '%".$this->edtSearch->Text."%'
       OR manufacturer like '%".$this->edtSearch->Text."%'
       OR size like '%".$this->edtSearch->Text."%'
       OR type like '%".$this->edtSearch->Text."%'
       OR status like '%".$this->edtSearch->Text."%')
       order by status ASC,
       purch_date DESC";
       $result = mysql_query($query1)or die(mysql_error());
       $qctr = 0;

        $arr = array();
        $arr2 = array();
        while($row = mysql_fetch_array($result))
          {
            $tire_id = $row['tire_id'];
            $tire_sn = $row['tire_SN'];
            $manu = $row['manufacturer'];
            $size = $row['size'];
            $type = $row['type'];
            $purchdate = $row['purch_date'];

            $purch = "<a href=tire_general_edit.php?tire_id=".$tire_id."&tire_sn=".$tire_sn.">".$purchdate."</a>";
            //$tire_snred = "<a href=tire_general_edit.php?tire_id=".$tire_id."&tire_sn=".$tire_sn.">".$tire_sn."</a>";
            $tools = "<a href=inventory_status.php?stock_id=".$stock_id."&stock_num=".$stock_num."><img src='image/status.png' title='status' no border></a>";

            //<a href=inventory_adjust_create.php?stock_id=".$stock_id."&stock_num=".$stock_num."><img src='image/status.png' title='status' no border></a>
            $query2 = "select * from veh_tire where tire_id='".$tire_id."'";
            $result2 = mysql_query($query2)or die(mysql_error());
            $qctr = mysql_num_rows($result2);
            //if($qctr > 0)

            $stat = $row['status'];

            /*if($stat==1)
            {
            $arr2[] = array(
                        'Tire ID' => $tire_sn.'<font color = red> (not available)</font>',
                        'Brand' => '<font color = red>'.$manu.'</font>',
                        'Size' => '<font color = red>'.$size.'</font>',
                        'Type' => '<font color = red>'.$type.'</font>',
                        'Date Purchased' => '<font color = red>'.$purchdate.'</font>'
                        );
            }
            else
            {*/
            if($stat==1)
            {
            $query_journal = "SELECT vehicle_id,location FROM tire_srvcejournal_tbl WHERE type='Mount' AND tire_id='".$tire_id."' ORDER BY journal_id DESC";
            $result_journal = mysql_query($query_journal) or die("JOURNAL ".mysql_error());
            $row_journal = mysql_fetch_array($result_journal);
            $veh_id = $row_journal['vehicle_id'];
            $location = $row_journal['location'];

            $query_veh = "SELECT veh_num FROM vehicle_tbl WHERE vehicle_id='".$veh_id."'";
            $result_veh = mysql_query($query_veh) or die("VEHICLE ".mysql_error());
            $row_veh = mysql_fetch_array($result_veh);
            $status = '<span style="color:red">Mounted on '.$location.' of vehicle:'.$row_veh['veh_num'].'</span>';

            }

            if($stat==0)
            {
             $status = 'Available';
            }

            if($_SESSION['access_tire']==1)
            {
            $tools = "<img
            onclick=window.location.href='tire_tread_wear_list.php?tire_id=".$tire_id."'
            src='image/tire_maint.png' title='Maintenance'
            style='cursor:pointer'>";
            }

            if($_SESSION['access_tire']==2)
            {
            $tools = "<img
            onclick=window.location.href='tire_tread_wear_list.php?tire_id=".$tire_id."'
            src='image/tire_maint.png' title='Maintenance'
            style='cursor:pointer'>
            <img onclick=js_deleteTire('".$tire_id."','".$_SESSION['company_id']."'); src='image/delete.png' title='delete' style='cursor:pointer'>";
            }

            $arr2[] = array(
                        'Date Purchased' => $purch,
                        'Tire ID' => $tire_sn,
                        'Brand' => $manu,
                        'Size' => $size,
                        'Type' => $type,
                        'Status' => $status,
                        'Tools' => $tools
                        );
            }

            $this->JTTireList->setCellData($arr2);


       }

       function imgAddJSMouseOut($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.images['imgAdd'].src="image/add_new.png"
       <?php

       }

       function imgAddJSMouseOver($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.images['imgAdd'].src="image/add_new_blue.png"
       <?php

       }

}

global $application;

global $tire_list;

//Creates the form
$tire_list=new tire_list($application);

//Read from resource file
$tire_list->loadResource(__FILE__);

//Shows the form
$tire_list->show();

?>